﻿namespace Voxel2Unity
{
    using System;
    using System.Runtime.InteropServices;
    using UnityEngine;

    [StructLayout(LayoutKind.Sequential)]
    public struct VoxelFace
    {
        public int X;
        public int Y;
        public int Z;
        public int Width;
        public int Height;
        public Direction direction;
        public VoxelFace(int x, int y, int z, int w, int h, Direction d)
        {
            this.X = (d != Direction.Right) ? x : (x + 1);
            this.Y = (d != Direction.Back) ? y : (y + 1);
            this.Z = (d != Direction.Up) ? z : (z + 1);
            this.Width = w;
            this.Height = h;
            this.direction = d;
        }

        public Vector3 MaxPoint
        {
            get
            {
                switch (this.direction)
                {
                    case Direction.Up:
                    case Direction.Down:
                        return new Vector3((float) (this.X + this.Width), (float) (this.Y + this.Height), (float) this.Z);

                    case Direction.Front:
                    case Direction.Back:
                        return new Vector3((float) (this.X + this.Width), (float) this.Y, (float) (this.Z + this.Height));

                    case Direction.Left:
                    case Direction.Right:
                        return new Vector3((float) this.X, (float) (this.Y + this.Width), (float) (this.Z + this.Height));
                }
                return Vector3.zero;
            }
        }
        public Vector2 MaxPoints2D
        {
            get
            {
                switch (this.direction)
                {
                    case Direction.Up:
                    case Direction.Down:
                        return new Vector2((float) (this.X + this.Width), (float) (this.Y + this.Height));

                    case Direction.Front:
                    case Direction.Back:
                        return new Vector2((float) (this.X + this.Width), (float) (this.Z + this.Height));

                    case Direction.Left:
                    case Direction.Right:
                        return new Vector2((float) (this.Y + this.Width), (float) (this.Z + this.Height));
                }
                return Vector2.zero;
            }
        }
        public Vector3[] Points
        {
            get
            {
                return new Vector3[] { new Vector3((float) this.X, (float) this.Z, (float) this.Y), (((this.direction != Direction.Left) && (this.direction != Direction.Right)) ? new Vector3((float) (this.X + this.Width), (float) this.Z, (float) this.Y) : new Vector3((float) this.X, (float) this.Z, (float) (this.Y + this.Width))), (((this.direction != Direction.Up) && (this.direction != Direction.Down)) ? new Vector3((float) this.X, (float) (this.Z + this.Height), (float) this.Y) : new Vector3((float) this.X, (float) this.Z, (float) (this.Y + this.Height))), (((this.direction != Direction.Left) && (this.direction != Direction.Right)) ? (((this.direction != Direction.Up) && (this.direction != Direction.Down)) ? new Vector3((float) (this.X + this.Width), (float) (this.Z + this.Height), (float) this.Y) : new Vector3((float) (this.X + this.Width), (float) this.Z, (float) (this.Y + this.Height))) : new Vector3((float) this.X, (float) (this.Z + this.Height), (float) (this.Y + this.Width))) };
            }
        }
        public int VoxelX
        {
            get
            {
                return ((this.direction != Direction.Right) ? this.X : (this.X - 1));
            }
        }
        public int VoxelY
        {
            get
            {
                return ((this.direction != Direction.Back) ? this.Y : (this.Y - 1));
            }
        }
        public int VoxelZ
        {
            get
            {
                return ((this.direction != Direction.Up) ? this.Z : (this.Z - 1));
            }
        }
    }
}

